<?php
/**
 * 订单处理类
 * Enter description here ...
 * @author admin
 *
 */
class OrderAction extends BaseAction{
	/**
	 * 工作台
	 * Enter description here ...
	 */
	function work(){
		$this->assign("title",'工作台');
		$state1=$this->getDataByState(1,'0,2');
		
		$state2=$this->getDataByState(2,'0,2');
		$this->assign("state1",$state1);
		$this->assign("state2",$state2);
	   //$msg=ExSession::getSession()->getRealName()."在".formatDate(time())."查看服务单。";
   		//ExLog::addLog($msg, 'TYPE_ORDER_VIEW');
		
		$this->display();
	}
	/**
	 * 根据类型得到
	 * Enter description here ...
	 * @param unknown_type $type
	 */
	function getDataByState($stype=1,$limit=''){
		$u_id=ExSession::getSession()->getUserId();
		$sst=D("Srv_team_members");
		$sst->find($u_id);
		if($sst->IS_BLOCK==1 || $sst->IS_DEL==1){//过滤锁定或删除
			return false;
			//$search["ST_ID"]=0;
		}else{
			$st_id=$sst->ST_ID;
			if($st_id){
				/*$st=D("Srv_team");
				$st->find($st_id);
				$s_ar_id=$st->ST_AR_ID;
				*/
				$st=D("srv_team_areas");
				$st1=array();
				$st1["ST_ID"]=$st_id;
				$stas=$st->where($st1)->select();
				if($stas){
					foreach ($stas as $val){
						if($s_ar_id==''){
							$s_ar_id=$val["AR_ID"];
						}else{
							$s_ar_id=$s_ar_id.",".$val["AR_ID"];
						}
					}
				}
			}
		}
		$order=D("Service_order");
		$search["ST_ID"]=$st_id;
		//待处理    规则：地区符合 并且没有服务队
		if($stype==1){
			$search["O_STATE"]=array('in',array(10,20));
		}else if($stype==2){
			$search["O_STATE"]=array('in',array(30));
		}else if($stype==3){
			$search["O_STATE"]=array('in',array(40,50,60,70,80));
		}
		
		
		if($stype==1){
			if(count($search)){
				if($limit){
					$list=$order->where($search)->order('CREATED_AT asc')->limit($limit)->select();
				}else{
					$list=$order->where($search)->order('CREATED_AT asc')->select();
				}
				
			}else{
				if($limit){
					$list=$order->order('CREATED_AT asc')->limit($limit)->select();
				}else{
					$list=$order->order('CREATED_AT asc')->select();
				}
			}
		}else if ($stype==2){
			if(count($search)){
				if($limit){
					$list=$order->where($search)->order('O_SRV_APPOINT_TIME asc')->limit($limit)->select();
				}else{
					$list=$order->where($search)->order('O_SRV_APPOINT_TIME asc')->select();
				}
				
			}else{
				if($limit){
					$list=$order->order('O_SRV_APPOINT_TIME asc')->limit($limit)->select();
				}else{
					$list=$order->order('O_SRV_APPOINT_TIME asc')->select();
				}
			}
		}
		else if ($stype==3){
			if(count($search)){
				if($limit){
					$list=$order->where($search)->order('O_SRV_TIME asc')->limit($limit)->select();
				}else{
					$list=$order->where($search)->order('O_SRV_TIME asc')->select();
				}
				
			}else{
				if($limit){
					$list=$order->order('O_SRV_TIME asc')->limit($limit)->select();
				}else{
					$list=$order->order('O_SRV_TIME asc')->select();
				}
			}
		}
		$out=array();
		if($list && count($list)){
			foreach ($list as $v){
				$v["O_SRV_APPOINT_TIME_1"]=formatDate($v["O_SRV_APPOINT_TIME"],'Y-m-d H:i');
				if($v["O_SRV_APPOINT_TIME"]){
					$v["O_SRV_APPOINT_TIME"]=$v["O_SRV_APPOINT_TIME"];
				}else{
					$v["O_SRV_APPOINT_TIME"]=$v["O_REQ_TIME"];
				}
				$AR_ID=$v["AR_ID"];
				$tmpData=ExUse::getArea($AR_ID);
				$STR=implode(' ',$tmpData);
				$v["O_AREA"]=$STR.' '.$v["O_ADDRESS"];
				$v["O_PRODUCT"]=$v["P_BRAND"].' '.$v["P_CATEGORY"].' '.$v["P_MODEL"];
				
				//去客户信息
				$__user=D("User");
				$__user->find($v["CU_ID"]);
				$v["CR_NAME"]=$__user->U_RNAME;
				$v["CR_MOBLILE"]=$__user->U_MOBILE;
				$out[]=$v;
			}
		}
		return $out;
		
	}
	
	function test(){
		echo "<pre>";
		print_r(date("Y-m-d H:i",'1363058280'));
		echo "</pre>";
		exit;
		
	}
	
	function yy(){
		$this->assign("title",'确定预约时间');
		$O_ID=$this->in("O_ID");
		$this->assign("o_id",$O_ID);
		
		$O_ID=$this->in("O_ID");
		$this->assign("O_ID",$O_ID);
		$ly=$this->in("ly");
		$this->assign("ly",$ly);
		//保存备注
		if($this->in("op")){
			$rev='n';
			$__date=$this->in("data");
			
			if($__date["Month"]<10){
				$__moth="0".$__date["Month"];
			}else{
				$__moth=$__date["Month"];
			}
			if($__date["Day"]<10){
				$__day="0".$__date["Day"];
			}else{
				$__day=$__date["Day"];
			}
			if($__date["Hours"]<10){
				$__Hours="0".$__date["Hours"];
			}else{
				$__Hours=$__date["Hours"];
			}
			if($__date["Minutes"]<10){
				$__Minutes="0".$__date["Minutes"];
			}else{
				$__Minutes=$__date["Minutes"];
			}
			$O_SRV_APPOINT_TIME=$__date["Year"]."-".$__moth."-".$__day." ".$__Hours.":".$__Minutes;
			//$O_ST_MEMO_EXT=strtotime($this->in("O_SRV_APPOINT_TIME"));
			$O_ST_MEMO_EXT=strtotime($O_SRV_APPOINT_TIME);
			$order1=D("Service_order");
			$order1->find($O_ID);
			$O_NO=$order1->O_NO;
			$order1->O_SRV_APPOINT_TIME=$O_ST_MEMO_EXT;
			$order1->O_STATE=C("ORDER_STATE.STATE_EXECUTING");//设置状态为进行中
			$order1->UPDATED_AT=time();
			if($order1->save()){
				$msg=ExSession::getSession()->getRealName()."在".formatDate(time())."处理服务单。";
	   			ExLog::addLog($msg,'MOBILE_TYPE_ORDER_EXECUTE',2,$O_ID,$O_NO);
	   			if($this->in("isf")){
	   				message("确定预约上门时间成功",'?g=Mobile&m=Order&a=finish&O_ID='.$O_ID."&ly=".$ly);
	   			}else{
	   				message("确定预约上门时间成功",'?g=Mobile&m=Order&a=work');
	   			}
				
			}
			else{
				if($this->in("ly")){
	   				message("确定预约上门时间失败",'?g=Mobile&m=Order&a=finish&O_ID='.$O_ID."&ly=".$ly);
	   			}else{
	   				message("确定预约上门时间失败",'?g=Mobile&m=Order&a=yy&O_ID={$O_ID}');
	   			}
				
			}
			exit;
		}
		$order=D("Service_order");
		$data=$order->where('O_ID='.$O_ID)->select();
		$_O_REQ_TIME='';
		$_O_SRV_APPOINT_TIME='';
		if($data){
			$tmpData=$data[0];
			$tmpData["O_STATE"]=$tmpData["O_STATE"];
			$tmpData["O_STATE_NAME"]=ExUse::getOrderState($tmpData["O_STATE"]);
			$tmpData["O_TYPE"]=ExUse::getOrderType($tmpData["O_TYPE"]);
			
			$tmpData["O_F_STATE"]=ExUse::getJsState($tmpData["O_F_STATE"]);
			$_O_REQ_TIME=$tmpData["O_REQ_TIME"];
			$_O_SRV_APPOINT_TIME=$tmpData["O_SRV_APPOINT_TIME"];
			$tmpData["O_REQ_TIME"]=formatDate($tmpData["O_REQ_TIME"]);
			$tmpData["O_SRV_B_TIME"]=formatDate($tmpData["O_SRV_B_TIME"]);
			$tmpData["O_SRV_TIME"]=formatDate($tmpData["O_SRV_TIME"]);
			
			//去地区
			$AR_ID=$tmpData["AR_ID"];
			$tData=ExUse::getArea($AR_ID);
			
			$STR=implode(' ',$tData);
			$tmpData["O_AREA"]=$STR.' '.$tmpData["O_ADDRESS"];
			$tmpData["O_PRODUCT"]=$tmpData["P_BRAND"].'，'.$tmpData["P_CATEGORY"].'，'.$tmpData["P_MODEL"];
			$tmpData["P_BUY_TIME"]=formatDate($tmpData["P_BUY_TIME"],'Y-m-d');
			$uname=ExUse::getUname($tmpData["CU_ID"],'U_NAME');
			$tmpData["CU_ID_Name"]='';
			if($uname){
				$tmpData["CU_ID_Name"]=$uname;
			}
			
			//只有服务队查看才能改变状态
			/*if($tmpData["O_STATE"]<30 && ExSession::getSession()->getRoleShortname()=='SRVTEAM'){
				$order=D("Service_order");
				$order->find($O_ID);
				$order->O_STATE=C("ORDER_STATE.STATE_EXECUTING");//设置状态为进行中
				if($order->save()){
					$msg=ExSession::getSession()->getRealName()."在".formatDate(time())."处理服务单。";
	   				ExLog::addLog($msg,'TYPE_ORDER_EXECUTE',2,$tmpData["O_ID"],$tmpData["O_NO"]);
				}
				
				
			}*/
		}
		//取服务队的电话
		$t_id=$tmpData["ST_ID"];
		$__team=D("Srv_team");
		$__team->find($t_id);
		$ST_MOBILE=$__team->ST_MOBILE;
		$ST_PHONE=$__team->ST_PHONE;
		$tmpData["ST_MOBILE"]=$ST_MOBILE;
		$tmpData["ST_PHONE"]=$ST_PHONE;
		$menus=getMenu();
		$this->assign('menu',$menus);
		
		$this->assign("data",$tmpData);
		$this->assign("Year",getYear());
		$this->assign("Month",getMonth());
		$this->assign("Hours",getHours());
		$this->assign("Minutes",getMinutes());
		
		if($this->in("ly")=='t'){
			//取当前时间
			$this->assign("CYear",getCurrentTime('y',$_O_REQ_TIME));
			$this->assign("CMonth",getCurrentTime('m',$_O_REQ_TIME));
			$this->assign("CDay",getCurrentTime('d',$_O_REQ_TIME));
			$this->assign("CHours",getCurrentTime('h',$_O_REQ_TIME));
			$this->assign("CMinutes",getCurrentTime('i',$_O_REQ_TIME));
		}else{
			if($_O_SRV_APPOINT_TIME){
				$this->assign("CYear",getCurrentTime('y',$_O_SRV_APPOINT_TIME));
				$this->assign("CMonth",getCurrentTime('m',$_O_SRV_APPOINT_TIME));
				$this->assign("CDay",getCurrentTime('d',$_O_SRV_APPOINT_TIME));
				$this->assign("CHours",getCurrentTime('h',$_O_SRV_APPOINT_TIME));
				$this->assign("CMinutes",getCurrentTime('i',$_O_SRV_APPOINT_TIME));
			}else{
				//取当前时间
				$this->assign("CYear",getCurrentTime('y'));
				$this->assign("CMonth",getCurrentTime('m'));
				$this->assign("CDay",getCurrentTime('d'));
				$this->assign("CHours",getCurrentTime('h'));
				$this->assign("CMinutes",getCurrentTime('i'));
			}
		}
		
		$this->display();
	}
	
	function finish(){
		$this->assign("title",'完成订单');
		$O_ID=$this->in("O_ID");
		
		$O_ID=$this->in("O_ID");
		$this->assign("O_ID",$O_ID);
		$this->assign("ly",$this->in("ly"));
		//保存备注
		if($this->in("op")){
			$rev='n';
			$data=$this->in("data");
			$__file_url='';
			if (isset($_FILES["ofile"]) && is_uploaded_file($_FILES["ofile"]["tmp_name"]) && $_FILES["ofile"]["error"] == 0) {
				//$__size=$_FILES["ofile"]["size"]/1000;
				//if(C("SYS_UPLOAD_CARD_SIZE")<$__size){
				//	message("文件大小不符合要求,");
				//}
				
				$__shijian=date("Ym",time());
				$up_url=C("SYS_UPLOAD_CARD_DIR").$__shijian;
				if(is_dir($up_url)){
					
				}else{
					mkdir($up_url,0777);
					
				}
				
				$order=D("Service_order");
				$order->find($O_ID);
				$o_no=$order->O_NO;
				if(!$o_no){
					$o_no=getOrderNumber();
				}
				$up_url.="/".$O_ID;
				if(is_dir($up_url)){
					
				}else{
					mkdir($up_url,0777);
					
				}
				
				$_file=basename($_FILES["ofile"]["name"]);
				
				$fileExt=getFileExt($_file);
				//$fileNotExt=getFileNoExt($__file);
				$__file=$o_no.".".$fileExt;
				$__url=$up_url."/".$__file;
				if(file_exists($__url)){
					$_rand=mt_rand(1, 10);
					$__file=$o_no."-".$_rand.".".$fileExt;
					$__url=$up_url."/".$__file;
				}
				if(move_uploaded_file($_FILES["ofile"]["tmp_name"], $__url)){
					$__file_url= $__url;
				}
				//message($__file_url,'?m=Mobile&a=finish&O_ID='.$O_ID);
			}
			
			if(is_array($data) && $data){
				
				if($data["Month"]<10){
					$__moth="0".$data["Month"];
				}else{
					$__moth=$data["Month"];
				}
				if($data["Day"]<10){
					$__day="0".$data["Day"];
				}else{
					$__day=$data["Day"];
				}
				if($data["Hours"]<10){
					$__Hours="0".$data["Hours"];
				}else{
					$__Hours=$data["Hours"];
				}
				if($data["Minutes"]<10){
					$__Minutes="0".$data["Minutes"];
				}else{
					$__Minutes=$data["Minutes"];
				}
				$O_SRV_TIME=$data["Year"]."-".$__moth."-".$__day." ".$__Hours.":".$__Minutes;
				$order=D("Service_order");
				$order->find($O_ID);
				$order->P_INSTALL_CARD=$__file_url;
				$order->P_BAR_CODE=$data["P_BAR_CODE"];
				$order->O_SRV_TIME=$O_SRV_TIME?strtotime($O_SRV_TIME):time();
				$order->O_ST_MEMO=$data["O_ST_MEMO"];
				$order->O_STUFF_DETAILS=$data["O_STUFF_DETAILS"];
				$order->O_COST=$data["O_COST"];
				$order->O_INSTALL_USER=$data["O_INSTALL_USER"];
				$order->O_STATE=40;
				$order->UPDATED_AT=time();
				
				$logOid=$order->O_ID;
				$logONo=$order->O_NO;
				if($order->save()){
					$rev='y';
					$msg=ExSession::getSession()->getStName()."在".formatDate(time())."处理服务单。改变状态为:".ExUse::getOrderState(40);
	   				ExLog::addLog($msg, 'TYPE_ORDER_CHANGE_STATE',2,$logOid,$logONo);
				}
			}
			if($rev=='y'){
				message("确定安装完成成功",'?g=Mobile&m=Order&a=work');
			}else{
				message("确定安装完成失败",'?g=Mobile&m=Order&a=finish&O_ID={$O_ID}');
			}
			exit;
		}
		$order=D("Service_order");
		$data=$order->where('O_ID='.$O_ID)->select();
		if($data){
			$tmpData=$data[0];
			$tmpData["O_STATE"]=$tmpData["O_STATE"];
			$tmpData["O_STATE_NAME"]=ExUse::getOrderState($tmpData["O_STATE"]);
			$tmpData["O_TYPE"]=ExUse::getOrderType($tmpData["O_TYPE"]);
			
			$tmpData["O_F_STATE"]=ExUse::getJsState($tmpData["O_F_STATE"]);
			
			$tmpData["O_REQ_TIME"]=formatDate($tmpData["O_REQ_TIME"]);
			$tmpData["O_SRV_B_TIME"]=formatDate($tmpData["O_SRV_B_TIME"]);
			$tmpData["O_SRV_TIME"]=formatDate($tmpData["O_SRV_TIME"]);
			
			//去地区
			$AR_ID=$tmpData["AR_ID"];
			$tData=ExUse::getArea($AR_ID);
			
			$STR=implode(' ',$tData);
			$tmpData["O_AREA"]=$STR.' '.$tmpData["O_ADDRESS"];
			$tmpData["O_PRODUCT"]=$tmpData["P_BRAND"].'，'.$tmpData["P_CATEGORY"].'，'.$tmpData["P_MODEL"];
			$tmpData["P_BUY_TIME"]=formatDate($tmpData["P_BUY_TIME"],'Y-m-d');
			$uname=ExUse::getUname($tmpData["CU_ID"],'U_NAME');
			$tmpData["CU_ID_Name"]='';
			if($uname){
				$tmpData["CU_ID_Name"]=$uname;
			}
			
			//只有服务队查看才能改变状态
			/*if($tmpData["O_STATE"]<30 && ExSession::getSession()->getRoleShortname()=='SRVTEAM'){
				$order=D("Service_order");
				$order->find($O_ID);
				$order->O_STATE=C("ORDER_STATE.STATE_EXECUTING");//设置状态为进行中
				if($order->save()){
					$msg=ExSession::getSession()->getRealName()."在".formatDate(time())."处理服务单。";
	   				ExLog::addLog($msg,'TYPE_ORDER_EXECUTE',2,$tmpData["O_ID"],$tmpData["O_NO"]);
				}
				
				
			}*/
		}
		//取服务队的电话
		$t_id=$tmpData["ST_ID"];
		$__team=D("Srv_team");
		$__team->find($t_id);
		$ST_MOBILE=$__team->ST_MOBILE;
		$ST_PHONE=$__team->ST_PHONE;
		$tmpData["ST_MOBILE"]=$ST_MOBILE;
		$tmpData["ST_PHONE"]=$ST_PHONE;
		$menus=getMenu();
		$this->assign('menu',$menus);
		
		$this->assign("data",$tmpData);
		//$this->assign("filesize",C("SYS_UPLOAD_CARD_SIZE"));
		
		$this->assign("Year",getYear());
		$this->assign("Month",getMonth());
		$this->assign("Hours",getHours());
		$this->assign("Minutes",getMinutes());
		
		//取当前时间
		$this->assign("CYear",getCurrentTime('y'));
		$this->assign("CMonth",getCurrentTime('m'));
		$this->assign("CDay",getCurrentTime('d'));
		$this->assign("CHours",getCurrentTime('h'));
		$this->assign("CMinutes",getCurrentTime('i'));
		
		$this->display();
	}
	
	function olist(){
		$this->assign("title",'单据查询');
		set_time_limit(0);
		$pageSize=10;
		$type=$this->in("type");
		if(!$type){
			$type=1;
		}
		$tname="--待处理";
		if($type==2){
			$tname="--进行中";
		}else if($type==3){
			$tname="--已完成";
		}
		$this->assign("title",'单据查询'.$tname);
		/*
		$zpage=$cpage*$page;
		$limit=$zpage.",".$pageCount;
		$type=$this->in("type");
		if(!$type){
			$type=1;
		}
		$list=$this->getDataByState($type,$limit);
		*/
		
		$u_id=ExSession::getSession()->getUserId();
		$sst=D("Srv_team_members");
		$sst->find($u_id);
		if($sst->IS_BLOCK==1 || $sst->IS_DEL==1){//过滤锁定或删除
			return false;
			//$search["ST_ID"]=0;
		}else{
			$st_id=$sst->ST_ID;
			if($st_id){
				/*$st=D("Srv_team");
				$st->find($st_id);
				$s_ar_id=$st->ST_AR_ID;
				*/
				$st=D("srv_team_areas");
				$st1=array();
				$st1["ST_ID"]=$st_id;
				$stas=$st->where($st1)->select();
				if($stas){
					foreach ($stas as $val){
						if($s_ar_id==''){
							$s_ar_id=$val["AR_ID"];
						}else{
							$s_ar_id=$s_ar_id.",".$val["AR_ID"];
						}
					}
				}
			}
		}
		$order=D("Service_order");
		$search["ST_ID"]=$st_id;
		//待处理    规则：地区符合 并且没有服务队
		if($type==1){
			$search["O_STATE"]=array('in',array(10,20));
		}else if($type==2){
			$search["O_STATE"]=array('in',array(30));
		}else if($type==3){
			$search["O_STATE"]=array('in',array(40,50,60,70,80));
		}
		//检索条件
		if($this->in("O_NO")){
			$this->assign("O_NO",$this->in("O_NO"));
			$search["O_NO"]=array("like","%".$this->in("O_NO")."%");
		}
		
		if($type==1){
			$__ordertime="CREATED_AT asc";
		}else if ($type==2){
			$__ordertime="O_SRV_APPOINT_TIME asc";
		}
		else if ($type==3){
			
			$__ordertime="O_SRV_TIME asc";
		}
		
		if($_GET['p']){
			if(count($search)){
				$list=$order->where($search)->page($_GET['p'].','.$pageSize)->order($__ordertime)->select();
			}else{
				$list=$order->page($_GET['p'].','.$pageSize)->order($__ordertime)->select();
			}
			
		}else{
			if(count($search)){
				$list=$order->where($search)->limit('0,'.$pageSize)->order($__ordertime)->select();
			}else{
				$list=$order->limit('0,'.$pageSize)->order($__ordertime)->select();
			}
		}
			
		
		//page使用的总数
		if(count($search)){
			//$pageList=$order->where($search)->select();
			$order1=D("Service_order");
			$pageList=$order1->where($search)->count('O_ID');
		}
		else{
			//$pageList=$order->select();
			$order1=D("Service_order");
			$pageList=$order1->count('O_ID');
		}
		
		
		$out=array();
		if($list && count($list)){
			foreach ($list as $v){
				$v["O_SRV_APPOINT_TIME_1"]=formatDate($v["O_SRV_APPOINT_TIME"],'Y-m-d H:i');
				$AR_ID=$v["AR_ID"];
				$tmpData=ExUse::getArea($AR_ID);
				$STR=implode(' ',$tmpData);
				$v["O_AREA"]=$STR.' '.$v["O_ADDRESS"];
				$v["O_PRODUCT"]=$v["P_BRAND"].' '.$v["P_CATEGORY"].' '.$v["P_MODEL"];
				
				//去客户信息
				$__user=D("User");
				$__user->find($v["CU_ID"]);
				$v["CR_NAME"]=$__user->U_RNAME;
				$v["CR_MOBLILE"]=$__user->U_MOBILE;
				$out[]=$v;
			}
		}
		
		import('ORG.Util.Page');
		//$count      = count($pageList);// 查询满足要求的总记录数
		$count      = $pageList;// 查询满足要求的总记录数
		$Page       = new Page($count,$pageSize);// 实例化分页类 传入总记录数和每页显示的记录数
		$Page->setConfig('theme', "总订单数 %totalRow%    &nbsp;|&nbsp;%nowPage%/%totalPage% 页     &nbsp;&nbsp;    %upPage% %downPage% %first%  %prePage%  %linkPage%  %nextPage% %end%");
		$show       = $Page->show();// 分页显示输出
		$this->assign('page',$show);// 赋值分页输出
		$this->assign("list",$out);
		$this->assign("type",$type);
		$this->display();
	}
	function search(){
		$this->assign("title",'单据查询');
		set_time_limit(0);
		$pageSize=10;
		
		
		$u_id=ExSession::getSession()->getUserId();
		$sst=D("Srv_team_members");
		$sst->find($u_id);
		if($sst->IS_BLOCK==1 || $sst->IS_DEL==1){//过滤锁定或删除
			return false;
			//$search["ST_ID"]=0;
		}else{
			$st_id=$sst->ST_ID;
			if($st_id){
				/*$st=D("Srv_team");
				$st->find($st_id);
				$s_ar_id=$st->ST_AR_ID;
				*/
				$st=D("srv_team_areas");
				$st1=array();
				$st1["ST_ID"]=$st_id;
				$stas=$st->where($st1)->select();
				if($stas){
					foreach ($stas as $val){
						if($s_ar_id==''){
							$s_ar_id=$val["AR_ID"];
						}else{
							$s_ar_id=$s_ar_id.",".$val["AR_ID"];
						}
					}
				}
			}
		}
		$order=D("Service_order");
		$search["ST_ID"]=$st_id;
		
		//检索条件
		if($this->in("O_NO")){
			$this->assign("O_NO",$this->in("O_NO"));
			$search["O_NO"]=array("like","%".$this->in("O_NO")."%");
		}
		
		$__ordertime="CREATED_AT asc";
		
		if($_GET['p']){
			if(count($search)){
				$list=$order->where($search)->page($_GET['p'].','.$pageSize)->order($__ordertime)->select();
			}else{
				$list=$order->page($_GET['p'].','.$pageSize)->order($__ordertime)->select();
			}
			
		}else{
			if(count($search)){
				$list=$order->where($search)->limit('0,'.$pageSize)->order($__ordertime)->select();
			}else{
				$list=$order->limit('0,'.$pageSize)->order($__ordertime)->select();
			}
		}
		
		
		//page使用的总数
		if(count($search)){
			//$pageList=$order->where($search)->select();
			$order1=D("Service_order");
			$pageList=$order1->where($search)->count('O_ID');
		}
		else{
			//$pageList=$order->select();
			$order1=D("Service_order");
			$pageList=$order1->count('O_ID');
		}
		
		
		$out=array();
		if($list && count($list)){
			foreach ($list as $v){
				$v["O_SRV_APPOINT_TIME_1"]=formatDate($v["O_SRV_APPOINT_TIME"],'Y-m-d H:i');
				$AR_ID=$v["AR_ID"];
				$tmpData=ExUse::getArea($AR_ID);
				$STR=implode(' ',$tmpData);
				$v["O_AREA"]=$STR.' '.$v["O_ADDRESS"];
				$v["O_PRODUCT"]=$v["P_BRAND"].' '.$v["P_CATEGORY"].' '.$v["P_MODEL"];
				
				//去客户信息
				$__user=D("User");
				$__user->find($v["CU_ID"]);
				$v["CR_NAME"]=$__user->U_RNAME;
				$v["CR_MOBLILE"]=$__user->U_MOBILE;
				$out[]=$v;
			}
		}
		import('ORG.Util.Page');
		//$count      = count($pageList);// 查询满足要求的总记录数
		$count      = $pageList;// 查询满足要求的总记录数
		$Page       = new Page($count,$pageSize);// 实例化分页类 传入总记录数和每页显示的记录数
		$Page->setConfig('theme', "总订单数 %totalRow%    &nbsp;|&nbsp;%nowPage%/%totalPage% 页     &nbsp;&nbsp;    %upPage% %downPage% %first%  %prePage%  %linkPage%  %nextPage% %end%");
		$show       = $Page->show();// 分页显示输出
		$this->assign('page',$show);// 赋值分页输出
		$this->assign("list",$out);
		$this->assign("type",$type);
		$this->display();
	}
	function xq(){
		$this->assign("title",'详情');
		$O_ID=$this->in("O_ID");
		$this->assign("O_ID",$O_ID);
		
		$order=D("Service_order");
		$data=$order->where('O_ID='.$O_ID)->select();
		if($data){
			$tmpData=$data[0];
			$tmpData["O_STATE"]=$tmpData["O_STATE"];
			$tmpData["O_STATE_NAME"]=ExUse::getOrderState($tmpData["O_STATE"]);
			$tmpData["O_TYPE"]=ExUse::getOrderType($tmpData["O_TYPE"]);
			
			$tmpData["O_F_STATE"]=ExUse::getJsState($tmpData["O_F_STATE"]);
			
			$tmpData["O_REQ_TIME"]=formatDate($tmpData["O_REQ_TIME"]);
			$tmpData["O_SRV_B_TIME"]=formatDate($tmpData["O_SRV_B_TIME"]);
			$tmpData["O_SRV_TIME"]=formatDate($tmpData["O_SRV_TIME"]);
			
			//去地区
			$AR_ID=$tmpData["AR_ID"];
			$tData=ExUse::getArea($AR_ID);
			
			$STR=implode(' ',$tData);
			$tmpData["O_AREA"]=$STR.' '.$tmpData["O_ADDRESS"];
			$tmpData["O_PRODUCT"]=$tmpData["P_BRAND"].'，'.$tmpData["P_CATEGORY"].'，'.$tmpData["P_MODEL"];
			$tmpData["P_BUY_TIME"]=formatDate($tmpData["P_BUY_TIME"],'Y-m-d');
			$uname=ExUse::getUname($tmpData["CU_ID"],'U_NAME');
			$tmpData["CU_ID_Name"]='';
			if($uname){
				$tmpData["CU_ID_Name"]=$uname;
			}
			
		}
		//取服务队的电话
		$t_id=$tmpData["ST_ID"];
		$__team=D("Srv_team");
		$__team->find($t_id);
		$ST_MOBILE=$__team->ST_MOBILE;
		$ST_PHONE=$__team->ST_PHONE;
		$tmpData["ST_MOBILE"]=$ST_MOBILE;
		$tmpData["ST_PHONE"]=$ST_PHONE;
		$menus=getMenu();
		$this->assign('menu',$menus);
		
		$this->assign("data",$tmpData);
		//$this->assign("filesize",C("SYS_UPLOAD_CARD_SIZE"));
		
		$this->display();
	}
}